< previous page page_428 next page >

Page 428
9f31265bb40b592b1929e18a47ab28e5.gif
   If Button.Key = "Cut" Then
      Clipboard.SetText txtString1.SelText
      txtString1.SelText = ""
   ElseIf Button.Key = "Copy" Then
      Clipboard.SetText txtString1.SelText
   ElseIf Button.Key = "Paste" Then
      txtString2.SelText = Clipboard.GetText
   End If
End Sub
When one of the buttons on the toolbar control is clicked, you first need to figure out which button was clicked and then you can write the code to interact with the Clipboard object. If the user clicks the cut button, you want to grab the selected text from the SelText property of the text box and pass that as a parameter to the Clipboard.SetText method. You then need to clear the SelText property of the text box, because the cut button was clicked. The code is the same for a copy operation, except you dont clear the SelText property. For a paste operation, you call the GetText method of the Clipboard object and put the value returned into the SelText property of another text box. This is a hard-coded example, so lets now look at one thats a little more generic.
The Screen.ActiveControl Property
In the Screen object are two properties that are pointers to other objects in your application: ActiveForm and ActiveControl. These two properties are constantly updated as you open forms, close forms, and click from one form (or control) to another. These objects are useful for creating generic routines that always act upon the currently active form or control.
As an example, suppose you want to allow cut, copy, and paste operations from any text box control on any form. Lets look at the example shown in Figure 21.6.
Examples Filename: ObjControl.frm
8160-0428a.gif
Figure 21.6
An 
Active Control example.

 
< previous page page_428 next page >

If you like this book, buy it!